package com.hc.java.time;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.*;

/**
 * 生成两周内每天的午夜时间戳（毫秒）
 */
public class MidnightTimestamps {
    public static void main(String[] args) {
        // 获取当前日期
        LocalDate today = LocalDate.now();

        // 生成两周内每天的午夜时间戳（毫秒）
        List<Long> midnightTimestamps = IntStream.range(0, 14)
                .mapToObj(i -> today.minusDays(i))
                .map(date -> date.atStartOfDay(ZoneId.systemDefault()))
                .map(ZonedDateTime::toInstant)
                .map(Instant::toEpochMilli)
                .collect(Collectors.toList());

        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
        midnightTimestamps.forEach(timestamp -> {
            String formatted = Instant.ofEpochMilli(timestamp)
                    .atZone(ZoneId.systemDefault())
                    .format(formatter);
            System.out.println(formatted + " -> " + timestamp);
        });
    }
}